/**
 * 控制台贷款产品数据统计控制器
 */
import tem from './index.html'
import G2 from 'g2'
import $_fn from '~plugins'
class chartsPieCtrl {
  constructor($scope) {
  	$scope.fn=function(list){
  		/*var data = [
          { value: 0.55, key: '按揭房短拆' },
          { value: 0.45, key: '押车' },
	      ];*/
	     var data=[];
	     var datas=list.data.consolePieChart.getLoanWayPie;
	     console.log('贷款方式',datas)
	     var nums=0
	     if(datas && datas.length){
	      	for(var i=0; i<datas.length; i++ ){
		      	nums+=parseInt(datas[i].count)
		      }
		      for(var j=0; j<datas.length;j++ ){
		      	data[j]={}
		      	data[j].value=datas[j].count/nums;
		      	data[j].key=datas[j].loan_way;
		      }
	      }
	     console.log('贷款方式',data)
	     
	     
	     
	      var Stat = G2.Stat;
	      var chart = new G2.Chart({
	          id: 'charts_dai',
	          forceFit: true,
	          plotCfg: {
	              margin: [90, 0, 60, 0]
	          },
	          height: 450,
	      });
	      chart.source(data);
	      // 重要：绘制饼图时，必须声明 theta 坐标系
	      chart.coord('theta', {
	          radius: 0.7, // 设置饼图的大小
	          inner: 0.6
	      });
	      chart.tooltip({
	          title: null
	      });
	      chart.legend({
	          position: 'top', // 设置图例的显示位置
	          spacingX: 20,    // 图例项之间的水平间距
	          dy:20,
	          title: null,     // 不展示图例 title
	          word: {
	              fill: '#656363',
	              fontSize: 14
	          }
	      });
	      chart.intervalStack()
	          .shape('burstPie')
	          .position(Stat.summary.percent('value'))
	          .color('key', ['#f3bc30', '#46ac49'])
	          .style({
	              stroke: '#fff',
	              lineWidth: 2
	          }).label('key*..percent',function(key, percent){
	          percent = (percent * 100).toFixed(2) + '%';
	          return key + ':' + percent;
	      });
	
	      chart.render();
  	}
  	
  	$scope.kongZhiTai($scope.fn)
  	
  	
  	
  	
     /* var data = [
          { value: 0.55, key: '按揭房短拆' },
          { value: 0.45, key: '押车' },
      ];
      var Stat = G2.Stat;
      var chart = new G2.Chart({
          id: 'charts_dai',
          forceFit: true,
          plotCfg: {
              margin: [90, 0, 60, 0]
          },
          height: 450,
      });
      chart.source(data);
      // 重要：绘制饼图时，必须声明 theta 坐标系
      chart.coord('theta', {
          radius: 0.7, // 设置饼图的大小
          inner: 0.6
      });
      chart.tooltip({
          title: null
      });
      chart.legend({
          position: 'top', // 设置图例的显示位置
          spacingX: 20,    // 图例项之间的水平间距
          dy:20,
          title: null,     // 不展示图例 title
          word: {
              fill: '#656363',
              fontSize: 14
          }
      });
      chart.intervalStack()
          .shape('burstPie')
          .position(Stat.summary.percent('value'))
          .color('key', ['#f3bc30', '#46ac49'])
          .style({
              stroke: '#fff',
              lineWidth: 2
          }).label('key*..percent',function(key, percent){
          percent = (percent * 100).toFixed(2) + '%';
          return key + ':' + percent;
      });

      chart.render();*/
  }
}


chartsPieCtrl.$inject = ['$scope','$rootScope','$timeout','$location','$interval']
module.exports = angular.module('directive.chartsDai', []).directive('chartsDai', function() {
    return {
        restrict: 'ECAM',
        replace: true,
        template: tem,
        controller: chartsPieCtrl
    }
}).name